<?php

/*
=====================================================
 FluxBB - Delux Board Converstations (DBC)
-----------------------------------------------------
 http://dbc-forum.com/
 http://fluxbb.org/
-----------------------------------------------------
 Copyright (c) 2010,2011 FluxBB - Delux Board Conversations (DBC)
-----------------------------------------------------
 Предсловие: Данный скрипт (DBC) не является работой с нуля, то 
 есть ядром скрипта всё также остаётся FuxBB,но теперь в оболочке
 DBC.
=====================================================
*/

// Collect some statistics from the database
if (file_exists(FORUM_CACHE_DIR.'cache_users.php'))
	include FORUM_CACHE_DIR.'cache_users.php';

if (!defined('DBC_USERS_LOADED'))
{
	if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
		require DBC_ROOT.'engine/cache.php';

	generate_users_cache();
	require FORUM_CACHE_DIR.'cache_users.php';
}

$result = $db->query('SELECT SUM(num_topics), SUM(num_posts) FROM '.$db->prefix.'forums') or error('Unable to fetch topic/post count', __FILE__, __LINE__, $db->error());

list($stats['total_topics'], $stats['total_posts']) = $db->fetch_row($result);

if ($DBC_user['g_view_users'] == '1')
	$stats['newest_user'] = '<a href="user_'.$stats['last_user']['id'].'">'.DBC_htmlspecialchars($stats['last_user']['username']).'</a>';
else
 $stats['newest_user'] = DBC_htmlspecialchars($stats['last_user']['username']);
$stats['newest_user'] = str_replace(DBC_htmlspecialchars($stats['last_user']['username']), colorize_group($stats['last_user']['username'], $stats['last_user']['group_id']), $stats['newest_user']);
?>
	   <table width="100%" cellspacing="0" border="0" cellpadding="0">
	   <tr>
		<td class="bgstats_top_left" align="left">&nbsp;</td>
		<td class="bgstats_top_center" align="left"><?php echo $lang_index['Board info'] ?></td>
		<td class="bgstats_top_right" align="left">&nbsp;</td>
	   </tr>
	   <tr>
		<td class="bgstats_left" valign="top" align="left">&nbsp;</td>
		<td class="bgstats_center" align="left">

	<table width="100%" cellspacing="0" border="0" cellpadding="0">
	<tr class="stats_info_border"><td class="stats_info_title" align="left"><div class="stats_info_title"><?php printf($lang_index['Online'])?>
<?php
if ($DBC_config['o_users_online'] == '1')
{
	$num_guests = count($online_guests);
	$num_bots = 0; 
	$num_users = count($online_users);
	$users = array();

	foreach ($online_guests as $online_id => $online_name)
	{
		if (substr($online_name, 0, 5) == '[Bot]')
		{
		   ++$num_bots;
		   $users[] = "\n\t\t\t\t".''.DBC_htmlspecialchars($online_name);
		}
	}
	echo "\t\t\t\t".'<span>'.sprintf($lang_index['Users online'], '<strong>'.forum_number_format($num_users).'</strong>').', '.sprintf($lang_index['Guests online'], '<strong>'.forum_number_format($num_guests).'</strong>').'</span>'."\n";
}
else
	echo "\t\t\t".'</dl>'."\n\t\t\t".'<div class="clearer"></div>'."\n";


?>
	</div></td></tr>
	<tr class="stats_info_border"><td align="left"><div class="index_stats">
<div onmouseover="$('#fhint1').fadeIn(0);" onmouseout="$('#fhint1').fadeOut(0);" style="position:relative;">
<?php

if ($DBC_config['o_users_online'] == '1')
{
	echo "\t\t\t".'</dl>'."\n\t\t\t".'<div class="clearer"></div>'."\n";
	// Fetch users online info and generate strings for output
	$num_guests = 0;
	$users = array();
	$result = $db->query('SELECT user_id, ident, u.group_id FROM '.$db->prefix.'online LEFT JOIN '.$db->prefix.'users AS u ON (ident=u.username) WHERE idle=0 ORDER BY ident', true) or error('Unable to fetch online list', __FILE__, __LINE__, $db->error());

	while ($DBC_user_online = $db->fetch_assoc($result))
	{
		if ($DBC_user_online['user_id'] > 1)
		{
			if ($DBC_user['g_view_users'] == '1')
				$users[] = "\n\t\t\t\t".'<a href="user_'.$DBC_user_online['user_id'].'" title="">'.DBC_htmlspecialchars($DBC_user_online['ident']).'</a>';
			else
				$users[] = "\n\t\t\t\t".''.DBC_htmlspecialchars($DBC_user_online['ident']);
			$users[count($users) - 1] = str_replace('">'.DBC_htmlspecialchars($DBC_user_online['ident']).'</a>', '">'.colorize_group($DBC_user_online['ident'], $DBC_user_online['group_id']).'</a>', $users[count($users) - 1]);

		}
		else
			++$num_guests;
	}

	if ($num_users + $num_bots > 0)
		echo "\t\t\t".''."\n\t\t\t\t".''."\t\t\t\t".implode(', ', $users).''."\n\t\t\t".''."\n";
	else
		echo "\t\t\t\t".'<span>'.sprintf($lang_index['no_users_online'], '').', '.sprintf($lang_index['Guest online'], '<strong>'.forum_number_format($num_guests).'</strong>').'</span>'."\n";


}
else
	echo "\t\t\t".''."\n\t\t\t".'<div class="clearer"></div>'."\n";
?>



</div></div></td></tr>
	</table>

<table border="0" cellpadding="0" cellspacing="0" style="width: 100%;"> 
<tr><td class="statsblock_bottom" valign="top" align="center" width="160">

<table class="statsblock_bottom" border="0" cellpadding="0" cellspacing="0" style="width: 97%;"> 
<tr><td align="center" width="140" style="width: 140px;min-width: 140px;">
	<div class="bstat"><ul class="reset">
	<li class="bfriends"><strong><?php echo $lang_index['User info'] ?></strong></li>
	<li class="bfriends"><span><?php printf($lang_index['Newest user'], $stats['newest_user']) ?></span></li>
	<li class="bfriends"><?php
if ($DBC_config['o_users_online'] == '1')
{
	$num_guests = count($online_guests);
	$num_bots = 0; 
	$num_users = count($online_users);
	$users = array();
	foreach ($online_guests as $online_id => $online_name)
	{
		if (substr($online_name, 0, 5) == '[Bot]')
		{
		   ++$num_bots;
		   $users[] = "\n\t\t\t\t".''.DBC_htmlspecialchars($online_name);
		}
	}
	echo "\t\t\t\t".'<span>'.sprintf($lang_index['Users online'], '<strong>'.forum_number_format($num_users).'</strong>').', '.sprintf($lang_index['Guests online'], '<strong>'.forum_number_format($num_guests).'</strong>').'</span>'."\n";
}
else
	echo "\t\t\t".''."\n\t\t\t".'<div class="clearer"></div>'."\n";
?></li>
	<li class="bfriends">

<?php

if ($DBC_config['o_users_online'] == '1')
{
	// Fetch users online info and generate strings for output
	$num_guests = count($online_guests);
	$num_bots = 0;
	$num_users = count($online_users);
	$users = array();

	@include FORUM_CACHE_DIR.'cache_maxusers.php';
	if (defined('DBC_MAXUSERS_LOADED'))
		echo "\t\t\t\t".'<span>'. $lang_index['Most online1'].' <strong>'.$stats['max_users'].'</strong><p><span  class="stats_info_title">'.$lang_index['Most online2'].' '.format_time($stats['max_users_time']).'</span></p></span>'."\n\t\t\t".''."\n";
}
else
	echo "\t\t\t".''."\n\t\t\t".'<div class="clearer"></div>'."\n";
?>
	</li>
	</ul></div></td>
	</tr></tbody></table>



</td><td class="statsblock_bottom" valign="top" align="center" width="160">


<table class="statsblock_bottom" border="0" cellpadding="0" cellspacing="0" style="width:97%;"> 
<tr><td align="center" width="140">
	<div class="bstat"><ul class="reset">
	<li class="bfriends"><strong><?php echo $lang_index['Board stats'] ?></strong></li>
	<li class="bfriends"><span><?php printf($lang_index['No of users'], '<strong>'.forum_number_format($stats['total_users']).'</strong>') ?></li>
	<li class="bfriends"><?php printf($lang_index['No of topics'], '<strong>'.forum_number_format($stats['total_topics']).'</strong>') ?></span></li>
	<li class="bfriends"><?php printf($lang_index['No of posts'], '<strong>'.forum_number_format($stats['total_posts']).'</strong>') ?></span></li>
	</ul></div></td>
</tr></tbody></table>

</td>






<td class="statsblock_bottom" valign="middle" align="right" width="460">


<table class="statsblock_bottom_2" cellpadding="0" cellspacing="0" style="width:200px;border: 1px dashed #E5E5E5;"> 
<tr><td align="center" style="border-bottom: 1px dashed #E5E5E5;" width="40" height="50"><img src="templates/Default/images/f_cat_read.png" alt=""/></td><td align="left" style="border-bottom: 1px dashed #E5E5E5;" class="sposts" width="160" height="50"><b><?php printf($lang_index['yes_posts'], '') ?></b></td></tr></li>
<tr><td align="center" width="40" height="50"><img src="templates/Default/images/f_cat_unread.png" alt=""/></td><td align="left" class="sposts" width="160" height="50"><b><?php printf($lang_index['no_posts'], '') ?></b></td></tr>
</tbody></table>

</td>



</tr></table>





	</td>
	<td class="bgstats_right" align="right">&nbsp;</td>
	</tr>
		<tr>
		<td class="bgstats_bot_left" align="left">&nbsp;</td>
		<td class="bgstats_bot_center" align="left">&nbsp;</td>
		<td class="bgstats_bot_right" align="left">&nbsp;</td>
		</tr>
	</table>